import React, {Component} from 'react';
import PropTypes from 'prop-types';
class TodoItem extends Component{

    constructor(props) {
        super(props);
        this.handleClick = this.handleClick.bind(this);
    }

    shouldComponentUpdate(nextProps, nextState) {
        if(nextProps.content !== this.props.content) {
            return true;
        }
        return false;
    }

    componentDidMount() {
        
    }

    render(){
        const {content} = this.props;
        return (
            <div onClick={this.handleClick}>{content}</div>
        )
    }

    handleClick(){
        const {deleteItem, index} = this.props;
        // this.props.deleteItem(this.props.index)
        deleteItem(index);
    }
}

TodoItem.propTypes = {
    content: PropTypes.string,
    deleteItem: PropTypes.func,
    index: PropTypes.number
}

TodoItem.defaultProps = {
    content: '啊啊啊'
}

export default TodoItem;